package com.uzai.console.web.wechatwork;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.wechatwork.wxq.wxgroup.AddManagerDto;
import com.uzai.console.dto.wechatwork.wxq.wxgroup.DelManagerDto;
import com.uzai.console.dto.wechatwork.wxq.wxgroupmenber.*;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.wechatwork.WxWorkGroupMemberService;
import com.uzai.console.vo.wechatwork.wxq.wxgroupmember.WxWorkGroupMemberInfoVo;
import com.uzai.console.vo.wechatwork.wxq.wxgroupmember.WxWorkGroupMemberRelationVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 企业微信群成员成员
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "企业微信群成员", tags = "企业微信|微信群成员")
@ApiSort(6)
@RestController
public class WxWorkGroupMemberController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(WxWorkGroupMemberController.class);

    @Autowired
    private WxWorkGroupMemberService wxWorkGroupMemberService;

    @ApiOperation(value = "查询微信群成员列表", notes = "查询微信群成员列表", response = WxWorkGroupMemberInfoVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/wxWorkGroupMember/findWxWorkGroupMemberList")
    public Object findWxWorkGroupMemberList(@RequestBody WxWorkGroupMemberQuery wxWorkGroupMemberQuery){
        return wxWorkGroupMemberService.findWxWorkGroupMemberList(wxWorkGroupMemberQuery, true);
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupMember, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "踢出该群", notes = "踢出该群")
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxWorkGroupMember/kickWxWorkGroupMember")
    public Object kickWxWorkGroupMember(@RequestBody WxWorkGroupMemberKickDto wxWorkGroupMemberKickDto){
        wxWorkGroupMemberService.kickWxWorkGroupMemberByMemberIdList(wxWorkGroupMemberKickDto);
        try {
            Thread.sleep(1000);
        }catch (Exception e){

        }
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupMember, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加好友", notes = "添加好友")
    @ApiOperationSupport(order = 2)
    @PostMapping("/wxWorkGroupMember/addFriend")
    public Object addFriend(@RequestBody WxWorkGroupMemberIdDto wxWorkGroupMemberIdDto){
        wxWorkGroupMemberService.addFriend(wxWorkGroupMemberIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.WxWorkGroupMember, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "加入黑名单(系统维护的黑名单)", notes = "加入黑名单(系统维护的黑名单)")
    @ApiOperationSupport(order = 4)
    @PostMapping("/wxWorkGroupMember/addBlacklist")
    public Object addBlacklist(@RequestBody WxWorkGroupMemberBlacklistDto wxWorkGroupMemberBlacklistDto){
        wxWorkGroupMemberService.addBlacklist(wxWorkGroupMemberBlacklistDto);

        try {
            //延迟0.5秒
            Thread.sleep(500);
        }catch (Exception e){

        }

        return true;
    }

    @ApiOperation(value = "查询邀请关系", notes = "查询邀请关系", response = WxWorkGroupMemberRelationVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/wxWorkGroupMember/findInviteRelation")
    public Object findInviteRelation(@RequestBody WxWorkGroupMemberIdDto wxWorkGroupMemberIdDto){
        return wxWorkGroupMemberService.findInviteRelation(wxWorkGroupMemberIdDto);
    }

    @ApiOperation(value = "加群黑名单(进入企业微信机器人中的群黑名单)", notes = "加群黑名单(进入企业微信机器人中的群黑名单)")
    @ApiOperationSupport(order = 6)
    @PostMapping("/wxWorkGroupMember/addGroupBlacklist")
    public Object addGrpupBlacklist(@RequestBody WxWorkGroupMemberGroupBlacklistDto wxWorkGroupMemberGroupBlacklistDto){
        wxWorkGroupMemberService.addGrpupBlacklist(wxWorkGroupMemberGroupBlacklistDto);
        return true;
    }

    @ApiOperation(value = "设置管理员", notes = "设置管理员")
    @ApiOperationSupport(order = 7)
    @PostMapping("/wxWorkGroupMember/setAdmin")
    public Object setAdmin(@RequestBody WxWorkGroupMemberSetAdminDto wxWorkGroupMemberSetAdminDto){
        wxWorkGroupMemberService.setAdmin(wxWorkGroupMemberSetAdminDto);
        return true;
    }


    @ApiOperation(value = "新增群管理员", notes = "新增群管理员")
    @ApiOperationSupport(order = 8)
    @PostMapping("/wxWorkGroupMember/addManager")
    public Object addManager(@RequestBody AddManagerDto addManagerDto){
        wxWorkGroupMemberService.addManager(addManagerDto);
        return true;
    }

    @ApiOperation(value = "删除群管理员", notes = "删除群管理员")
    @ApiOperationSupport(order = 9)
    @PostMapping("/wxWorkGroupMember/delManager")
    public Object delManager(@RequestBody DelManagerDto delManagerDto){
        wxWorkGroupMemberService.delManager(delManagerDto);
        return true;
    }

}
